package com.jakewharton.rxbinding4.component;

import static com.jakewharton.rxbinding4.internal.Preconditions.checkNotNull;

import com.jakewharton.rxbinding4.InitialValueObservable;

import io.reactivex.rxjava3.annotations.CheckReturnValue;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.functions.Consumer;
import ohos.agp.components.Rating;

/**
 * Rx rating
 */
public final class RxRating {
    /**
     * Create an observable of the rating changes on {@code view}.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     * <p>
     * <em>Note:</em> A value will be emitted immediately on subscribe.
     *
     * @param view view
     * @return the initial value observable
     */
    @CheckReturnValue
    @NonNull
    public static InitialValueObservable<Float> progressbarChange(@NonNull Rating view) {
        checkNotNull(view, "view == null");
        return new RatingProgressChangeObservable(view);
    }

    /**
     * Create an observable of the rating change events on {@code view}.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     * <p>
     * <em>Note:</em> A value will be emitted immediately on subscribe.
     *
     * @param view view
     * @return the initial value observable
     */
    @CheckReturnValue
    @NonNull
    public static InitialValueObservable<RatingProgressChangeEvent> progressChangeEvents(@NonNull Rating view) {
        checkNotNull(view, "view == null");
        return new RatingProgressChangeEventObservable(view);
    }

    /**
     * An action which sets the rating of {@code view}.
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     *
     * @param view view
     * @return the consumer
     */
    @CheckReturnValue
    @NonNull
    public static Consumer<? super Float> score(@NonNull Rating view) {
        checkNotNull(view, "view == null");
        return view::setScore;
    }

    /**
     * An action which sets whether {@code view} is an indicator (thus non-changeable by the user).
     * <p>
     * <em>Warning:</em> The created observable keeps a strong reference to {@code view}. Unsubscribe
     * to free this reference.
     *
     * @param view view
     * @return the consumer
     */
    @CheckReturnValue
    @NonNull
    public static Consumer<? super Boolean> isOperable(@NonNull Rating view) {
        checkNotNull(view, "view == null");
        return view::setIsOperable;
    }

    private RxRating() {
        throw new AssertionError("No instances.");
    }
}
